package jam4j;

import java.util.HashMap;
import java.util.Map;

/**
 * Any of the hardware platforms recognized by Jam4J and exposed to scripts in
 * the {@code OSPLAT} variable.
 * 
 * @see jam4j.lang.SpecialVariable#OSPLAT
 * 
 * @author Luke Maurer
 */
public enum Platform {
    PPC("ppc", "PowerPC"),
    PPC64("ppc64"),
    AXP("alpha"),
    X86("x86", "i386"),
    AMD64("amd64", "x86_64"),
    SPARC("sparc"),
    MIPS("mips"),
    ARM("arm", "armv41"),
    IA64,
    _390 {
        public String toString() {
            return "390";
        }
    }
    ;
    
    private final String[] javaNames;
    
    private Platform(String ... javaNames) {
        this.javaNames = javaNames;
    }
    
    private static final Map<String, Platform> JAVA_NAME_MAP;
    
    static {
        JAVA_NAME_MAP = new HashMap<String, Platform>();
        for (Platform platform : values())
            for (String name : platform.javaNames)
                JAVA_NAME_MAP.put(name, platform);
    }
    
    /**
     * @return The hardware platform running Jam4J.
     */
    public static Platform hostPlatform() {
        final String javaName = System.getProperty("os.arch");
        return JAVA_NAME_MAP.get(javaName);
    }
}
